package cn.yuan.order.service.impl;

import cn.yuan.basic.service.impl.BaseServiceImpl;
import cn.yuan.basic.util.PageList;
import cn.yuan.order.domain.PetAcquisitionOrder;
import cn.yuan.order.query.PetAcquisitionOrderQuery;
import cn.yuan.order.service.IPetAcquisitionOrderService;
import cn.yuan.org.domain.Employee;
import cn.yuan.org.domain.Shop;
import cn.yuan.org.mapper.EmployeeMapper;
import cn.yuan.org.mapper.ShopMapper;
import cn.yuan.user.domain.User;
import cn.yuan.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PetAcquistionOrderServiceImpl extends BaseServiceImpl<PetAcquisitionOrder> implements IPetAcquisitionOrderService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private ShopMapper shopMapper;
    @Override
    public PageList<PetAcquisitionOrder> queryUserOrder(PetAcquisitionOrderQuery query, Long logininfoId) {
        //设置用户id
        User user = userMapper.loadByLoginInfoId(logininfoId);
        query.setUserId(user.getId());
        //都要做分页查询，只是查询条件不一样
        return super.queryForPage(query);
    }

    /**
     *    一个接口
     管理员：一个接口
     平台管理员-所有的
     店铺管理员-自己店铺 shop_id
     店铺员工-自己   emp_id
     * @param query
     * @param loginInfoId
     * @return
     */
    @Override
    public PageList<PetAcquisitionOrder> queryOrder(PetAcquisitionOrderQuery query, Long logininfoId) {
        //如果是店铺管理员，设置shopId
        Employee employee = employeeMapper.loadByLoginInfoId(logininfoId);
        Shop shop =  shopMapper.loadByAdmin_id(employee.getId());
        if(shop!=null){
            query.setShopId(shop.getId());
        }else {
            if(employee.getShop_id()!=null){
                query.setEmpId(employee.getId());
            }
        }
        //如果是店员empId*shopId
        return super.queryForPage(query);
    }

}
